import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        double p = in.nextDouble();

        // 查找所有因子
        List<Integer> factors = new ArrayList<>();
        for(int i = 1; i <= n; i++) {
            if (n % i == 0) {
                factors.add(i);
            }
        }

        double minExpected = Double.MAX_VALUE;
        int bestK = 1;

        // 考虑所有可能的k（包括1和真因子）
        for(int k : factors) {
            double expected = n/k * Math.pow(1-p, k) + (1 - Math.pow(1-p, k)) * n;
            if(expected < minExpected) {
                minExpected = expected;
                bestK = k;
            }
        }

        System.out.println(bestK);
        in.close();
    }
}